Uec3.OrderServiceWindow = Ext.extend(Ext.app.Module, {
	id : 'orderService',
	type : 'common/orderService',

	/**
	 * Initialize this module. This function is called at startup (page
	 * load/refresh).
	 */
	openServicesItemsWindow:function(id){
	
	var desktop = Uec3.App.getDesktop();
	desktop.launchWindowByParam("serviceItems", {
				id : id,
				winId : id
			});
	
},
	
	
	getComponents : function(rowIndex) {
		var btnPanel;
		var orderService_grid;
		var orderService_ds;
		var orderService_form;
		var orderServiceList = [];//保存修改过的记录

		var renderCertifyItemAct = function(value, cellmeta, record, rowIndex,
				columnIndex, store) {
			var id = record.get('id');
			var str = "<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\"orderService\").openServiceItemsWindow("
					+ id + ");'>查看明细</a>";
			return str;

		};			
	
		function deleteDatailFromArr(quotationList,data){
			Ext.each(orderServiceList,function(item,index){
				var id = item['id'];
				if(data['id'] == id){
					 orderServiceList.splice(index,1);
					 return false;
				}					    
			});
		}
			
		
		
		var getAndRestoreQuotation = function() {


			orderService_ds = new Ext.data.Store({

				proxy : new Ext.data.HttpProxy({
							url : Uec3.App.Constants.homeUrl
									+ '/quotation/queryOrderService!query.do'
						}),
				pruneModifiedRecords : true,
				baseParams : {
					start : 0,
					limit : 20
				},
				reader : new Ext.data.JsonReader({
							totalProperty : 'totalProperty',
							root : 'root'
						}, [

						{
									name : 'id'
								}, 
								{
									name : 'name'
								}, {
									name : 'code'
								}, {
									name : 'price'
								},								{
									name : 'gmtBegin',
									type :'string'
								}, {
									name : 'gmtEnd',									
									type :'string'
								}{
									name : 'description'
								}]),
				remoteSort : true,

				// 默认排序字段
				sortInfo : {
					field : "id",
					direction : "asc"
				}

			});

		};

		var componentInitsOrderService = function() {
			
			
			var checkboxModel = new Ext.grid.CheckboxSelectionModel({
						moveEditorOnEnter : true,
						singleSelect : false
					});

			// 初始化inventory表格对象

			var quotation_colModel = new Ext.grid.ColumnModel([

							checkboxModel,
			                {
				                header : "操作",
				                width : 120,
				                dataIndex : 'act',
				                renderer:renderCertifyItemAct
				                 },
							{
								header : "套餐名称",
								width : 100,
								dataIndex : 'name'
							}, {
								header : "套餐编码",
								width : 100,
								dataIndex : 'code'
							}, {
								header : "价格",
								align : 'right',
								width : 90,
								dataIndex : 'price'
							}, {
								header : "description",
								id : 'description',
								width : 80,
								dataIndex : 'description',
								align : 'right'
							},{
								header : "开始时间",
								width : 100,		
								dataIndex : 'gmtBegin'
							}, {
								header : "截止时间",
								width : 100,				
								dataIndex : 'gmtEnd'
							}

					]);

			// create the Grid
			orderService_grid = new Ext.grid.GridPanel({
						region : 'center',
						iconCls : 'icon-grid',
						enableColumnMove : false,
						enableColumnMoveResize : false,
						stripeRows : true,
						height : 360,
						// autoExpandColumn:'gmtModify',
						clicksToEdit : 1,
						loadMask : {
							msg : "...加载数据中"
						},
						store : orderService_ds,
						cm : quotation_colModel,
						sm : checkboxModel,
						viewConfig : {
							// forceFit : true,
							columnsText : '显示的列',
							scrollOffset : 30,
							sortAscText : '升序',
							sortDescText : '降序'
						},
						bbar : new Ext.PagingToolbar({
									pageSize : 20,
									store : orderService_ds,
									displayInfo : true,
									display : true,
									displayMsg : '第 {0} - {1} 条  共 {2} 条',
									emptyMsg : "没有记录"									
								})

					});
			// 把数据加载到store中
			orderService_ds.load();

			var choose = new Ext.Button(

			{
						text : '全选',
						id : 'chooseButton',
						anchor : '80%',
						handler : function() {
							checkboxModel.selectAll();
						},
						style : "margin-left:12px"

					});

			var noChoose = new Ext.Button(

			{
						text : '取消选择',
						id : 'noChooseButton',
						anchor : '80%',
						handler : function() {
							checkboxModel.clearSelections();
						},
						style : "margin-left:12px"

					});

			var saveModify = new Ext.Button(

			{
				text : '订购',
				anchor : '80%',
				id : 'saveModifyButton',
				style : "margin-left:12px",
				handler : function() {					
					if(!Ext.isEmpty(quotationList)){						
						var q = Ext.encode(orderServiceList); 
						alert(q);
						Ext.Ajax.request({

								url : Uec3.App.Constants.homeUrl+ '/quotation/queryQuotation!update.do',
								timeout:1800000,
								success : function(res) {
									var result = Ext.decode(res.responseText);
									if (result.success == "OK") {
										Ext.Msg.alert('提示', "保存成功");
										orderService_grid.getView().refresh();
									} else {
										Ext.Msg.alert("提示", result.failure);
										orderService_grid.getView().refresh();
									}
								},
								failure : function(res) {
									Ext.Msg.alert('失败', "网络出现异常，请重先连接");
								},
								params : {queryParam : q}
					    });
					}else{
					   Ext.MessageBox.alert("提示","未有修改明细....");
					}					
				}

			});

			// 填充按钮

			btnPanel = new Ext.Panel({
						labelAlign : 'right',
						cls : 'x-panel',
						layoutConfig : {},
						frame : true,
						buttonAlign : 'center',
						buttons : [choose, noChoose, publican, notPublican,
								publicanToCustomer, saveModify]

					});
		};
        
		// 初始化表单对象
		orderService_form = new Ext.form.FormPanel({
			labelAlign : 'right',
			border : false,
			layout : 'form',
			frame : true,
			autoHeight : true,
			width : '100%',
			url : '',
			items : [orderService_grid,btnPanel]
		});
		   

		var controlOrderServiceEvent = function() {

		};

		getAndRestoreOrderService();

		componentInitsOrderService();

		controlOrderServiceEvent();

		return orderService_form;

	},

	/**
	 * Create this modules window here.
	 */
	createWindow : function() {
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('orderService');
		if (!win) {
			win = desktop.createWindow({
				id : 'orderService',
				title : '报价列表',
				width : document.body.clientWidth * 0.9,
				height : document.body.clientHeight * 0.9,
				iconCls : 'acc-icon',
				shim : false,
				animCollapse : false,
				constrainHeader : true,
				maximizable : true,
				taskbuttonTooltip : "报价列表",
				layout : "fit",
				listeners : {
					'resize' : function(win, width, height) {
						if (width < 800 || height < 500) {
							win.setWidth(800);
							win.setHeight(500);
							this.items.get(1).items.get(3).setHeight(500 - 150);
						} else {
							this.items.get(1).items.get(3).setHeight(height- 150);
						}
					}
				},
				tools : [{
							id : 'refresh',
							handler : Ext.emptyFn,
							scope : this
						}],
				items : [this.getComponents()]
			});

		}
		win.show();

	}
});